<template>
  <div class="device">
    <div>设备的类型：{{name}}</div>
    <div>设备的型号：{{model}}</div>
    <div>设备的生产厂商：{{vendor}}</div>
    <div>系统语言信息：{{language}}</div>
    <div>系统的供应商信息：{{vendor1}}</div>
    <div>系统版本信息：{{version}}</div>

    <div>uuid：{{uuid}}</div>
    <div>系统音量：{{getVolume}}</div>
    <div>是否屏幕常亮：{{isWakelock}}</div>

    <div>屏幕水平方向的密度：{{dpiX}}</div>
    <div>屏幕垂直方向的密度：{{dpiY}}</div>

    <div>屏幕高度物理分辨率：{{height}}</div>
    <div>屏幕宽度物理分辨率：{{width}}</div>

    <div>备当前连接的网络类型：{{getNetworkType}}</div>


    <div>
      <button @click="beep">发出蜂鸣声</button>
      <button @click="dial">拨打电话</button>
      <button @click="setWakelock">设置应用是否屏幕常亮</button>
      <button @click="setVolume">设置音量</button>
      <input type="number" v-model="Volume" placeholder="请输入音量">
      <button @click="vibrate">设备振动</button>
    </div>
  </div>
</template>

<script>
  export default {
    name: "device",
    data() {
      return {
        name: "",
        model: "",
        vendor: "",
        uuid: "",
        getVolume: "",
        Volume: "",
        isWakelock: "",
        dpiX: "",
        dpiY: "",
        height: "",
        width: "",
        getNetworkType: "",
        language: "",
        vendor1: "",
        version: "",
      }
    },
    mounted() {
      this.pageCrate();
    },
    methods: {
      pageCrate() {
        this.name = plus.os.name;
        this.model = plus.device.model;
        this.vendor = plus.device.vendor;
        this.uuid = plus.device.uuid;
        this.getVolume = plus.device.getVolume();
        this.isWakelock = plus.device.isWakelock();

        this.dpiX = plus.screen.dpiX;
        this.dpiY = plus.screen.dpiY;
        this.height = plus.screen.resolutionHeight;
        this.width = plus.screen.resolutionWidth;

        this.language = plus.os.language;
        this.vendor1 = plus.os.vendor;
        this.version = plus.os.version;

        var types = {};
        types[plus.networkinfo.CONNECTION_UNKNOW] = "Unknown connection";
        types[plus.networkinfo.CONNECTION_NONE] = "None connection";
        types[plus.networkinfo.CONNECTION_ETHERNET] = "Ethernet connection";
        types[plus.networkinfo.CONNECTION_WIFI] = "WiFi connection";
        types[plus.networkinfo.CONNECTION_CELL2G] = "Cellular 2G connection";
        types[plus.networkinfo.CONNECTION_CELL3G] = "Cellular 3G connection";
        types[plus.networkinfo.CONNECTION_CELL4G] = "Cellular 4G connection";
        this.getNetworkType = types[plus.networkinfo.getCurrentType()]
      },
      beep() {
        plus.device.beep(2);
      },
      dial() {
        plus.device.dial(10086, true);
      },
      setWakelock() {
        plus.device.setWakelock(true);
      },
      setVolume() {
        if (this.Volume <= 1 && this.Volume >= 0) {
          plus.device.setVolume(this.Volume);
        } else {
          mui.alert('值要为0-1范围', "", "", "", "div");
        }
      },
      vibrate() {
        plus.device.vibrate(1500);
      }
    }
  }
</script>

<style scoped lang="scss">
  .device {
    width: 100%;
    height: 100%;
    padding: 32px;

    div {
      text-wrap: normal;
    }
  }
</style>
